package com.qpcy.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.qpcy.utils.ResponseResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.qpcy.entity.Style;
import com.qpcy.service.StyleService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;
import static com.qpcy.entity.table.StyleTableDef.STYLE;

/**
 * 风格 控制层。
 *
 * @author LENOVO
 * @since 2024-10-19
 */
@RestController
@RequestMapping("/style")
public class StyleController {

    @Autowired
    private StyleService styleService;

    /**
     * 获取所有风格
     *
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult getAll() {
        QueryWrapper queryWrapper = QueryWrapper.create().orderBy(Style::getSort, true);
        return ResponseResult.success(styleService.list(queryWrapper));
    }

    /**
     * 保存风格
     *
     * @param style
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody Style style) {
        return ResponseResult.success(styleService.save(style));
    }

    /**
     * 修改风格
     *
     * @param style
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Style style) {
        return ResponseResult.success(styleService.updateById(style));
    }

    /**
     * 删除风格
     *
     * @param styleId
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(int styleId) {
        return ResponseResult.success(styleService.removeById(styleId));
    }



}
